package com.taobao.search.feignclient;

import com.taobao.base.model.RestResponse;
import com.taobao.search.model.dto.GoodsDto;
import com.taobao.search.model.dto.StoreDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class HomeServiceClientFallbackFactory implements FallbackFactory<HomeServiceClient> {



    @Override
    public HomeServiceClient create(Throwable cause) {

        return new HomeServiceClient() {

            @Override
            public RestResponse<List<GoodsDto>> getAllGoods() {
                log.error("添加课程索引发生熔断,索引信息:,熔断异常:{}",cause.toString(),cause);
                //走降级了返回 false
                return RestResponse.validfail("添加课程索引发生熔断,熔断异常:"+cause);
            }

            @Override
            public RestResponse<StoreDto> getStoreById(Integer storeId) {
                log.error("添加课程索引发生熔断,索引信息:{},熔断异常:{}",storeId, cause.toString(),cause);
                //走降级了返回 false
                return RestResponse.validfail("添加课程索引发生熔断,熔断异常:"+cause);
            }
        };
    }
}
